package com.kx.kxblog.controller;

import com.kx.kxblog.annotation.DefaultResult;
import com.kx.kxblog.annotation.PermissionLimit;
import com.kx.kxblog.bean.Result;
import com.kx.kxblog.entity.User;
import com.kx.kxblog.entity.vo.UserLoginVO;
import com.kx.kxblog.entity.vo.UserRegisterVO;
import com.kx.kxblog.enums.Permission;
import com.kx.kxblog.enums.ResultCode;
import com.kx.kxblog.enums.SystemContextKey;
import com.kx.kxblog.exception.ResultException;
import com.kx.kxblog.service.UserService;
import com.kx.kxblog.util.SystemContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户")
@RequestMapping("/user")
@RestController
public class UserController extends AbstractController<User, Integer, UserService> {

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public User login(@RequestBody @Validated UserLoginVO userLoginVO){
        return service.login(userLoginVO);
    }


    @PostMapping("/register")
    @ApiOperation("用户注册")
    public User register(@RequestBody @Validated UserRegisterVO userRegisterVO){
        return service.register(userRegisterVO);
    }

    @PermissionLimit
    @GetMapping("/me")
    @ApiOperation("获取当前登录用户信息")
    public User me(){
        return SystemContext.getLoginUser();
    }

    @Override
    @PermissionLimit(Permission.NO)
    @ApiOperation(value = "", hidden = true)
    public User create(User entity) {
        return super.create(entity);
    }

    @Override
    @PermissionLimit(Permission.NO)
    @ApiOperation(value = "", hidden = true)
    public User modifyById(User entity) {
        return super.modifyById(entity);
    }

    @GetMapping("/test")
    @ApiOperation(value = "", response = Result.class)
    public User test(){
        User user = new User();
        user.setNickName("666");
        return user;
    }
//    @Override
//    protected void setService(UserService service){
//        super.setService(service);
//    }
}
